package www.qiyue.sm;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import www.qiyue.utils.UUIDGenerator;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
public class smtest {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @RequestMapping("smtes")
    public void smtest(){
        String message;

        String id="8a54069675dfd4320175dfdc3a8b0002";
        String rentSql = "select * from  ais_rentincreasingtwo where contract_id = '"
                + id + "' order by start_date asc";
        List<Map<String, Object>> rentList = jdbcTemplate.queryForList(rentSql);

        String sql="SELECT *, (TIMESTAMPDIFF(DAY,start_date,fee_start_date)+TIMESTAMPDIFF(DAY,fee_end_date,end_date)) as mzdate from ais_contractapproval where id ='"+id+"'";
        Map<String, Object> map = jdbcTemplate.queryForMap(sql);
        BigDecimal contract_acreage = new BigDecimal(map.get("contract_acreage") == null ? "0" : map.get("contract_acreage") + "");
        BigDecimal contract_period = new BigDecimal(map.get("contract_period") == null ? "0" : map.get("contract_period") + "");
        BigDecimal mzdate = new BigDecimal(map.get("mzdate") == null ? "0" : map.get("mzdate") + "");
        BigDecimal min_rent_price = new BigDecimal(map.get("min_rent_price") == null ? "0" : map.get("min_rent_price") + "");
        BigDecimal max_rent_price = new BigDecimal(map.get("max_rent_price") == null ? "0" : map.get("max_rent_price") + "");
        BigDecimal contract_price = new BigDecimal(map.get("contract_price") == null ? "0" : map.get("contract_price") + "");
        String general_manager = map.get("general_manager")==null?null:map.get("general_manager") + "";
        String board_resolution = map.get("board_resolution")==null?null:map.get("board_resolution") + "";
        String enabled_con_template = map.get("enabled_con_template")==null?null:map.get("enabled_con_template") + "";
        String supplementary_file = map.get("supplementary_file")==null?null:map.get("supplementary_file") + "";
        String supplementary = map.get("supplementary")==null?null:map.get("supplementary") + "";
        String custom_template = map.get("custom_template")==null?null:map.get("custom_template") + "";
        String rentifems = map.get("rentifems")==null?null:map.get("rentifems") + "";
        BigDecimal max_dayRent = contract_acreage.multiply(max_rent_price);

        if (rentList.size()>0){
            if ("01".equals(rentifems)){
                message="有租金递增条款,请核查租金递增选项";
                System.out.println(message);
            }
        }
        if (contract_price.doubleValue()<min_rent_price.doubleValue()){
            message="合同单价低于第一年基准价";
            System.out.println(message);
        }
        if (contract_period.doubleValue()>12){
            if (rentList.size()>0){

            }
        }

        if (contract_acreage.doubleValue()>=2000){
            if (StringUtils.isEmpty(general_manager)){
                message="必须上传总经理办公会决议";
                System.out.println(message);
            }
        }
        if (contract_period.doubleValue()>=36 && contract_period.doubleValue()<72){
            if (StringUtils.isEmpty(general_manager)){
                message="必须上传总经理办公会决议";
                System.out.println(message);
            }
        }
        if (contract_period.doubleValue()>=72){
            if (StringUtils.isEmpty(board_resolution)){
                message="必须上传董事会决议";
                System.out.println(message);
            }
        }
        if (mzdate.doubleValue()>90){
            if ( StringUtils.isEmpty(board_resolution)){
                message="必须上传董事会决议";
                System.out.println(message);
            }
        }
        if ("N".equals(enabled_con_template)){
            if (StringUtils.isEmpty(custom_template)){
                message="必须上传自定义模板";
                System.out.println(message);
            }
        }
        if ("Y".equals(supplementary)){
            if (StringUtils.isEmpty(supplementary_file)){
                message="必须上传合同补充条款";
                System.out.println(message);
            }
        }
    }
    public  void  setabc(){
        ArrayList<Map<String, Object>> list = new ArrayList<>();
        for (Map<String, Object> map : list) {
            int integer = Integer.parseInt(map.get("integer") + "");
            if (integer>12){

            }
        }
    }

    public static void main(String[] args) {

        String generate = UUIDGenerator.generate();

        System.out.println(generate);
    }
}
